package cn.flexui.flexuiserver.controller.web;

import cn.dev33.satoken.stp.StpUtil;
import cn.flexui.flexuiserver.common.ResponseResultGenerator;
import cn.flexui.flexuiserver.common.convert.UserInfoConvert;
import cn.flexui.flexuiserver.domain.ResponseResult;
import cn.flexui.flexuiserver.domain.entity.UserInfo;
import cn.flexui.flexuiserver.domain.vo.UserInfoVO;
import cn.flexui.flexuiserver.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author apeto
 * @since 2024-09-17 07:08:21
 */
@Tag(name = "用户信息")
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private UserInfoConvert userInfoConvert;

    @Operation(summary = "获取用户信息")
    @GetMapping("/get")
    public ResponseResult<UserInfoVO> get() {
        long userId = StpUtil.getLoginIdAsLong();
        UserInfo result = userInfoService.getById(userId);
        return ResponseResultGenerator.success(userInfoConvert.toVO(result));
    }
}
